package com.sunshine.androidjavapractise.learn;

import android.util.Log;

import java.util.Enumeration;
import java.util.Vector;

/**
 * customer
 */
public class Customer {
    private static final String TAG = Customer.class.getSimpleName();
    private static boolean DEG = Log.isLoggable(TAG, Log.DEBUG);
    private String name;
    private Vector<Rental> rentalVector = new Vector<>();

    public Customer(String name) {
        this.name = name;
    }

    public void addRental(Rental rental) {
        rentalVector.addElement(rental);
    }

    public String getName() {
        return name;
    }

    public String statement() {
        double totalAmount = 0;
        int frequentRenterPoints = 0;
        Enumeration<Rental> rentalEnumeration = rentalVector.elements();
        String result = "Rental Record for " + getName() + "\n";
        while (rentalEnumeration.hasMoreElements()) {
            double thisAmount = 0;
            Rental rental = rentalEnumeration.nextElement();
            switch (rental.getMovie().getPrice()) {
                case Movie.CHILDRENS:
                    thisAmount += 2;
                    if (rental.getDayRented() > 2) {
                        thisAmount += (rental.getDayRented() - 2) * 1.5;
                    }
                    break;
                case Movie.REGULATOR:
                    thisAmount += rental.getDayRented() * 3;
                    break;
                case Movie.RELEASE_NEW:
                    thisAmount += 1.5;
                    if (rental.getDayRented() > 3) {
                        thisAmount += (rental.getDayRented() - 3) * 1.5;
                    }
                    break;
                default:
                    Log.e(TAG, "can't run here");
                    break;
            }
            frequentRenterPoints++;
            if ((rental.getMovie().getPrice() == Movie.REGULATOR) && (rental.getDayRented() > 1)) {
                frequentRenterPoints++;
            }
            result += "\t" + rental.getMovie().getTitle() + "\t" + thisAmount + "\n";
            totalAmount += thisAmount;
        }
        result += "Total amount is " + totalAmount + "\n";
        result += "You earned " + frequentRenterPoints + " points \n";
        return result;
    }
}
